package com.sdyeda.readiot.iotinfo;

import java.util.Date;
import java.util.Map;

import com.sdyeda.readiot.config.Setting;

public class IotData {
	private String id;		//编号（用于管理）
	private String iotid;	//设备编号
	private Date time;	//数据时间（从设备返回）
	private String type;	//设备类型（用于管理）
	private String typetext;//设备类型文本（浸润线、测斜仪...)
	private double temp;	//温度
	private double value;	//测量值
	private double offset;	//偏移值
	private double strain;	//应变频率
	private double compen;	//补偿频率
	private String unit;	//单位
	private String sid;		//自编号
	private String stype;	//类型
	
	private Date readtime = new Date(); //读取时间
	private boolean success; 
	private String com;
	
	private int[] rainvalues;
	
	private int readtimes;
	
	public IotData()
	{
		setReadtime(new Date());
		setSuccess(false);
	}

	public IotData(IotInfo iotinfo)
	{
		//System.out.println(iotinfo.getIp());
		setId(iotinfo.getId());
		if(iotinfo.isUsedtu()) {
			setCom(String.format("%s(%d)",iotinfo.getIp(),iotinfo.getPort()));
		}
		else {
			setCom(iotinfo.getCom());		//ip新增此处。
		}
		setIotid(iotinfo.getIotid());
		setType(iotinfo.getType());
		
		setReadtime(new Date());
		//setSuccess(null);
	}

	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	public String getIotid() {
		return iotid;
	}

	public void setIotid(String iotid) {
		this.iotid = iotid;
	}
	public String getType() {
		return type;
	}

	@SuppressWarnings("unchecked")
	public void setType(String type) {
		this.type = type;
		// Map<String, String> a = (Map<String, String>) (Setting.Get(Setting.IOTTYPE));
		try {
			setTypetext(((Map<String, String>) (Setting.Get(Setting.IOTTYPE))).get(type));
		} catch (Exception e) {
		}
	}

	public String getTypetext() {
		return typetext;
	}

	public void setTypetext(String typetext) {
		this.typetext = typetext;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public double getTemp() {
		return temp;
	}

	public void setTemp(double temp) {
		this.temp = temp;
	}

	public double getValue() {
		return value;
	}

	public void setValue(double value) {
		this.value = value;
	}

	public double getOffset() {
		return offset;
	}

	public void setOffset(double offset) {
		this.offset = offset;
	}

	public double getStrain() {
		return strain;
	}

	public void setStrain(double strain) {
		this.strain = strain;
	}

	public double getCompen() {
		return compen;
	}

	public void setCompen(double compen) {
		this.compen = compen;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}
	
	public String getSid() {
		return sid;
	}

	public void setSid(String sid) {
		this.sid = sid;
	}

	public String getStype() {
		return stype;
	}

	public void setStype(String stype) {
		this.stype = stype;
	}

	public Date getReadtime() {
		return readtime;
	}

	public void setReadtime(Date readtime) {
		this.readtime = readtime;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getCom() {
		return com;
	}

	public void setCom(String com) {
		this.com = com;
	}


	public int getReadtimes() {
		return readtimes;
	}

	public void setReadtimes(int readtimes) {
		this.readtimes = readtimes;
	}

	public int[] getRainvalues() {
		return rainvalues;
	}

	public void setRainvalues(int[] rainvalues) {
		this.rainvalues = rainvalues;
	}
	
	/*
	@SuppressWarnings("deprecation")
	public double getRainValue() {
		if(getRainvalues() == null || getRainvalues().length<23) {
			return 0;
		}
		else {
			return (double) getRainvalues()[getTime().getHours()];
		}
	}

	@SuppressWarnings({ "deprecation" })
	public double getRainValue2() {
		if(getRainvalues() == null || getRainvalues().length<23) {
			return 0;
		}
		else {
			//需注意0点
			if(getTime().getHours() ==0) {
				return 0;
			}
			return (double) getRainvalues()[getTime().getHours()-1];
		}
	}
	*/
}
